/**
 * GTTableViewController.m
 *
 * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License 
 * at http://www.mozilla.org/MPL/
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
 * either express or implied. See the License for the specific language governing rights and limitations 
 * under the License.
 *
 * The Original Code is gcast-toolbox4iphone.
 *
 * The Initial Developers of the Original Code is Giannandrea Castaldi.
 */

#import "GTTableViewController.h"
#import "UIView+GTExtension.h"
#import "UITableView+GTExtension.h"

@interface GTTableViewController ()
@property(nonatomic,retain) NSString *backgroundImageName;
@property(nonatomic,retain) UITableView *tableView;
@end

@implementation GTTableViewController
@synthesize backgroundImageName, tableView;

+ (id)viewController {
  return [[[self alloc] init] autorelease];
}

+ (id)viewControllerWithTitle:(NSString*)aTitle backgroundImageName:(NSString*)aBackgroundImageName {
  return [[[self alloc] initWithTitle:aTitle backgroundImageName:aBackgroundImageName] autorelease];
}

- (id)initWithTitle:(NSString*)aTitle backgroundImageName:(NSString*)aBackgroundImageName {
  if ((self = [super init])) {
    self.title = aTitle;
    self.backgroundImageName = aBackgroundImageName;
  }
  return self;
}

- (void)loadView {
  self.view = [UIView viewWithBackgroundImageNamed:self.backgroundImageName];
  self.view.contentMode = UIViewContentModeTop;  
  self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;  
  
  self.tableView = [[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped] autorelease];
  self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;  
  self.tableView.backgroundColor = [UIColor clearColor];  
  self.tableView.allowsSelection = TRUE;
  self.tableView.dataSource = self;
  self.tableView.delegate = self;  
  [self.view addSubview:self.tableView];
  [self.tableView putAtTheTopAndFillSuperview];  
}

- (void)dealloc {
  [backgroundImageName release];
  [tableView release];
  [super dealloc];
}

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  [self.tableView deselectCurrentRow];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  return nil;
}

@end
